package com.qm.console.controller.rest;

import com.qm.console.controller.dto.BaseRsp;
import com.qm.console.pubdef.dto.channel.ChannelUpdateAdminDTO;
import com.qm.console.service.channel.ChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/channels")
public class ChannelController {
    @Autowired
    private ChannelService ChannelService;

    @GetMapping("/list")
    public BaseRsp listChannelAdmin(@RequestParam(value = "limit", required = false, defaultValue = "20") String limit,
                                    @RequestParam(value = "bundleId", required = false) String bundleId,
                                    @RequestParam(value = "channelName", required = false) String channelName,
                                    @RequestParam(value = "page", required = false, defaultValue = "1") String page){
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("pageSize", limit);
        paramMap.put("pageNum", page);
        if (bundleId != null && !bundleId.equals("")){
            paramMap.put("bundleId", bundleId);
        }
        if (channelName != null && !channelName.equals("")){
            paramMap.put("channelName", channelName);
        }
        return ChannelService.listChannelAdmin(paramMap);
    }

    @PostMapping("/update")
    public BaseRsp updateChannelAdmin(@RequestBody ChannelUpdateAdminDTO updateDTO){
        return ChannelService.updateChannelAdmin(updateDTO);
    }

    @DeleteMapping("delete")
    public BaseRsp DeleteChannelAdmin(@RequestBody String id){
        return ChannelService.DeleteChannelAdmin(id);
    }

    @PutMapping("/status")
    public BaseRsp updateChannelStatusAdmin(@RequestBody String updateParam){
        return ChannelService.updateChannelStatusAdmin(updateParam);
    }
}
